﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:UI="clr-namespace:OpenLS.Spreadsheet.UI" xmlns:Internals="clr-namespace:OpenLS.Spreadsheet.UI.Internals" xmlns:Spreadsheet="clr-namespace:OpenLS.Spreadsheet;assembly=OpenLS.Spreadsheet" xmlns:Internals1="clr-namespace:OpenLS.Chart.UI.Internals;assembly=OpenLS.Chart.UI" xmlns:Internals2="clr-namespace:OpenLS.Drawing.UI.Internals;assembly=OpenLS.Drawing.UI" xmlns:UI1="clr-namespace:OpenLS.Drawing.UI;assembly=OpenLS.Drawing.UI" xmlns:UI2="clr-namespace:OpenLS.UI;assembly=OpenLS.UI"
                    xmlns:Resources="clr-namespace:OpenLS.Spreadsheet.UI.Internals.Resources"
                    x:Class="OpenLS.Spreadsheet.UI.Internals.BordersFormatterResources">
    <ResourceDictionary.MergedDictionaries>
        <Internals:ColorResources></Internals:ColorResources>
    </ResourceDictionary.MergedDictionaries>
    <DataTemplate DataType="{x:Type UI:BordersFormatter}">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"></ColumnDefinition>
                <ColumnDefinition></ColumnDefinition>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"></RowDefinition>
                <RowDefinition></RowDefinition>
            </Grid.RowDefinitions>
            <GroupBox Header="{x:Static Resources:UIStringTable.Line}" Grid.RowSpan="2">
                <StackPanel>
                    <Label Content="{x:Static Resources:UIStringTable.Style_}"/>
                    <ListBox
                        ItemsSource="{Binding Source={x:Type Spreadsheet:BorderStyle}, Converter={x:Static Internals1:ChartConverters.EnumEnumerator}}"
                        SelectedItem="{Binding BorderStyle}">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <Grid Background="Transparent" Height="20" Width="58">
                                    <TextBlock Text="{x:Static Internals1:UIStringTable.None}" Visibility="Collapsed" Name="noneTextBox"></TextBlock>

                                    <Line  VerticalAlignment="Center" X2="50" Margin="4" Stroke="Black" StrokeThickness="{Binding Converter={x:Static Internals:SpreadsheetConverters.BorderStyleToThicknessConverter}}"
                                      StrokeDashArray="{Binding Converter={x:Static Internals:SpreadsheetConverters.BorderStyleToDashConverter}}" Name="line">
                                    </Line>
                                
                                </Grid>
                                <DataTemplate.Triggers>
                                    <DataTrigger Binding="{Binding}" Value="{x:Static Spreadsheet:BorderStyle.None}">
                                        <Setter TargetName="noneTextBox" Property="Visibility" Value="Visible"></Setter>
                                        <Setter TargetName="line" Property="Visibility" Value="Collapsed"></Setter>
                                    </DataTrigger>
                                </DataTemplate.Triggers>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                        <ListBox.ItemsPanel>
                            <ItemsPanelTemplate>
                                <WrapPanel Width="122"></WrapPanel>
                            </ItemsPanelTemplate>
                        </ListBox.ItemsPanel>
                    </ListBox>
                    <Label Content="{x:Static Internals2:UIStringTable.Color_}"/>
                    <ComboBox  x:Name="self" 
                               ItemsSource="{Binding ElementName=self, Converter={x:Static Internals:SpreadsheetConverters.StandardTextColorConverter}, Path=(UI:SpreadsheetElement.Workbook)}"
                               SelectedItem="{Binding Color}">
                        <ComboBox.ItemTemplate>
                            <DataTemplate DataType="{x:Type Spreadsheet:SpreadsheetColor}">
                                <Rectangle Height="12"  Width="12"  Name="r">
                                    <Rectangle.Fill>
                                        <MultiBinding Converter="{x:Static Internals:SpreadsheetConverters.ColorToBrushConverter}">
                                            <Binding/>
                                            <Binding RelativeSource="{RelativeSource Self}" Path="(UI1:DrawingElement.ColorScheme)"/>
                                            <Binding RelativeSource="{RelativeSource Self}" Path="(UI1:DrawingElement.ColorScheme)"/>
                                        </MultiBinding>
                                    </Rectangle.Fill>
                                </Rectangle>
                            </DataTemplate>

                        </ComboBox.ItemTemplate>
                        <ComboBox.ItemsPanel>
                            <ItemsPanelTemplate>
                                <WrapPanel MaxWidth="180"/>
                            </ItemsPanelTemplate>
                        </ComboBox.ItemsPanel>
                        <ComboBox.ItemContainerStyle>
                            <Style TargetType="{x:Type ComboBoxItem}">
                                <Setter Property="Margin" Value="1"/>
                                <Setter Property="Template">
                                    <Setter.Value>
                                        <ControlTemplate TargetType="{x:Type ComboBoxItem}">
                                            <Border BorderBrush="Gray" BorderThickness="1" Name="extBorder" Margin="{TemplateBinding Margin}">
                                                <Grid>
                                                    <ContentPresenter x:Name="Header" Margin="0" Width="12"
                                            VerticalAlignment="Center" ContentSource="Content" />
                                                    <Border BorderBrush="Transparent" BorderThickness="1"  Name="intBorder">
                                                    </Border>
                                                </Grid>
                                            </Border>
                                            <ControlTemplate.Triggers>
                                                <Trigger Property="IsHighlighted" Value="True">
                                                    <Setter Property="Background" Value="{DynamicResource {x:Static UI2:OfficeBrushes.MenuHoverBackgroundKey}}" />
                                                    <Setter Property="BorderBrush" Value="Orange" TargetName="extBorder" />
                                                    <Setter Property="BorderBrush" Value="White" TargetName="intBorder" />
                                                    <Setter Property="UI2:HighlightElement.IsHighlighted" Value="True"/>
                                                </Trigger>
                                            </ControlTemplate.Triggers>
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                        </ComboBox.ItemContainerStyle>
                    </ComboBox>


                </StackPanel>
            </GroupBox>
            <GroupBox Header="{x:Static Resources:UIStringTable.Presets}" Grid.Column="1">
                <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
                    <StackPanel.Resources>
                        <Style TargetType="{x:Type Button}">
                            <Setter Property="Width" Value="37"></Setter>
                            <Setter Property="Height" Value="37"></Setter>
                            <Setter Property="Margin" Value="5">
                            </Setter>
                        </Style>
                    </StackPanel.Resources>
                    <Button Command="{Binding NoBorderCommand}">
                        <Path StrokeThickness="2" Stroke="Gray" StrokeDashArray="1 1" Data="M0 0 L30 0 L 30 30 L0 30 L0 0 L15 0 L 15 30 M 0 15 L 30 15"></Path>
                    </Button>
                    <Button Command="{Binding OutlineBorderCommand}">
                        <Grid>
                            <Path StrokeThickness="2" Stroke="Gray" StrokeDashArray="1 1" Data="M0 0 L30 0 L 30 30 L0 30 L0 0 L15 0 L 15 30 M 0 15 L 30 15"></Path>
                            <Path StrokeThickness="2" Stroke="Gray" Data="M0 0 L30 0 L 30 30 L0 30 L0 0 "></Path>
                        </Grid>
                    </Button>
                    <Button Command="{Binding InsideBorderCommand}">
                        <Grid>
                            <Path StrokeThickness="2" Stroke="Gray" StrokeDashArray="1 1" Data="M0 0 L30 0 L 30 30 L0 30 L0 0 L15 0 L 15 30 M 0 15 L 30 15"></Path>
                            <Path StrokeThickness="2" Stroke="Black" Data="M15 0 L 15 30 M 0 15 L 30 15"></Path>
                        </Grid>
                    </Button>
                </StackPanel>
            </GroupBox>
         <!--   <GroupBox Header="{x:Static Internals:UIStringTable.Border}" Grid.Column="1" Grid.Row="1"></GroupBox> -->
            <GroupBox Header="{x:Static Resources:UIStringTable.Border2}" Grid.Column="1" Grid.Row="1">
                <Grid SnapsToDevicePixels="True">
                    <Grid.Resources>
                        <Style TargetType="{x:Type Button}">

                            <Setter Property="Margin" Value="5"></Setter>
                            <Setter Property="Width" Value="20"></Setter>
                            <Setter Property="Height" Value="20"></Setter>
                            <Setter Property="Command" Value="{Binding ToggleBorderCommand}"></Setter>
                        </Style>
                        <Style TargetType="{x:Type Button}" x:Key="Invisible">

                            <Setter Property="Command" Value="{Binding ToggleBorderCommand}"></Setter>
                            <Setter Property="Opacity" Value="0"></Setter>
                        </Style>
                        <Style TargetType="{x:Type Path}" x:Key="back1">
                            <Setter Property="Data" Value="M0 0 L14 0 L 14 14 L 0 14 L 0 0 L 0 7 L 14 7 M 7 0 L 7 14" />
                        	<Setter Property="StrokeDashArray" Value="1 1" />
                        	<Setter Property="Stroke" Value="Black" />
                        </Style>
                        <Style TargetType="{x:Type Line}" >
                            <Setter Property="Stroke" Value="Black" />
                        </Style>
                    </Grid.Resources>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"></ColumnDefinition>
                        <ColumnDefinition Width="70"></ColumnDefinition>
                        <ColumnDefinition Width="70"></ColumnDefinition>
                        <ColumnDefinition Width="70"></ColumnDefinition>
                        <ColumnDefinition Width="Auto"></ColumnDefinition>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="70"></RowDefinition>
                        <RowDefinition Height="70"></RowDefinition>
                        <RowDefinition Height="70"></RowDefinition>
                        <RowDefinition Height="Auto"></RowDefinition>
                    </Grid.RowDefinitions>
                    <Button CommandParameter="{x:Static Spreadsheet:BorderType.LeftEdge}" Grid.Column="1" Grid.Row="3" HorizontalAlignment="Left" >
                        <Button.Content>
                            <Grid>
                                <Path Style="{StaticResource back1}"/>
                                <Line Y2="14"></Line>
                            </Grid>
                        </Button.Content>
                    </Button>
                    <Button CommandParameter="{x:Static Spreadsheet:BorderType.RightEdge}"  Grid.Column="3" Grid.Row="3" HorizontalAlignment="Right">
                        <Button.Content>
                            <Grid>
                                <Path Style="{StaticResource back1}"/>
                                <Line Y2="14" X1="14" X2="14"></Line>
                            </Grid>
                        </Button.Content>
                    </Button>
                    <Button CommandParameter="{x:Static Spreadsheet:BorderType.TopEdge}"  Grid.Column="0" Grid.Row="0" VerticalAlignment="Top">
                        <Button.Content>
                            <Grid>
                                <Path Style="{StaticResource back1}"/>
                                <Line X2="14"></Line>
                            </Grid>
                        </Button.Content>
                    </Button>
                    <Button CommandParameter="{x:Static Spreadsheet:BorderType.BottomEdge}"  Grid.Column="0" Grid.Row="2" VerticalAlignment="Bottom">
                        <Button.Content>
                            <Grid>
                                <Path Style="{StaticResource back1}"/>
                                <Line  Y1="14" Y2="14" X2="14"></Line>

                            </Grid>
                        </Button.Content>
                    </Button>
                    <Button CommandParameter="{x:Static Spreadsheet:BorderType.InsideHorizontal}"  Grid.Column="0" Grid.Row="1" VerticalAlignment="Center">
                        <Button.Content>
                            <Grid>
                                <Path Style="{StaticResource back1}"/>
                                <Line Y1="7" Y2="7" X2="14"></Line>

                            </Grid>
                        </Button.Content>
                    </Button>
                    <Button CommandParameter="{x:Static Spreadsheet:BorderType.InsideVertical}"  Grid.Column="2" Grid.Row="4" HorizontalAlignment="Center">
                        <Button.Content>
                            <Grid>
                                <Path Style="{StaticResource back1}"/>
                                <Line Y2="14" X1="7" X2="7"></Line>

                            </Grid>
                        </Button.Content>
                    </Button>
                	<Button CommandParameter="{x:Static Spreadsheet:BorderType.DiagonalDown}"  Grid.Column="4" Grid.Row="4" HorizontalAlignment="Center">
                        <Button.Content>
                            <Grid>
                                <Line Y2="14" X2="14" ></Line>

                            </Grid>
                        </Button.Content>

                    </Button>
                	<Button CommandParameter="{x:Static Spreadsheet:BorderType.DiagonalUp}"  Grid.Column="0" Grid.Row="4" HorizontalAlignment="Center">
                        <Button.Content>
                            <Grid>
                                <Line Y2="14" X1="14" ></Line>

                            </Grid>
                        </Button.Content>

                    </Button>
                	<ItemsControl Margin="9" ItemsSource="{Binding Lines}" Grid.Column="1" Grid.ColumnSpan="3" Grid.Row="0" Grid.RowSpan="3">
                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <Canvas Width="210" Height="210"></Canvas>
                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>
                    </ItemsControl>
                    <Button Style="{StaticResource Invisible}" CommandParameter="{x:Static Spreadsheet:BorderType.DiagonalDown}" HorizontalAlignment="Center"  VerticalAlignment="Center"   Grid.Column="1" Grid.Row="0" Grid.ColumnSpan="3" Grid.RowSpan="3"  Height="20" Width="300">
                        <Button.LayoutTransform>
                            <RotateTransform Angle="45"></RotateTransform>
                        </Button.LayoutTransform>
                    </Button>
                    <Button Style="{StaticResource Invisible}" CommandParameter="{x:Static Spreadsheet:BorderType.DiagonalUp}" HorizontalAlignment="Center"  VerticalAlignment="Center" Grid.Column="1" Grid.Row="0" Grid.RowSpan="3" Grid.ColumnSpan="3"  Height="20" Width="300">
                        <Button.LayoutTransform>
                            <RotateTransform Angle="-45"></RotateTransform>
                        </Button.LayoutTransform>
                    </Button>
                    <Button Style="{StaticResource Invisible}" CommandParameter="{x:Static Spreadsheet:BorderType.LeftEdge}" Grid.Column="1" Grid.Row="0" Grid.RowSpan="3" HorizontalAlignment="Left"  Width="20"></Button>
                    <Button Style="{StaticResource Invisible}" CommandParameter="{x:Static Spreadsheet:BorderType.LeftEdge}" Grid.Column="1" Grid.Row="0" Grid.RowSpan="3" HorizontalAlignment="Left"  Width="20"></Button>
                    <Button Style="{StaticResource Invisible}" CommandParameter="{x:Static Spreadsheet:BorderType.RightEdge}" Grid.Column="3" Grid.Row="0" Grid.RowSpan="3" HorizontalAlignment="Right"  Width="20"></Button>
                    <Button Style="{StaticResource Invisible}" CommandParameter="{x:Static Spreadsheet:BorderType.InsideVertical}" Grid.Column="2" Grid.Row="0" Grid.RowSpan="3" HorizontalAlignment="Center"  Width="29"></Button>
                    <Button Style="{StaticResource Invisible}" CommandParameter="{x:Static Spreadsheet:BorderType.TopEdge}" Grid.Column="1" Grid.Row="0" Grid.ColumnSpan="3" VerticalAlignment="Top"  Height="20"></Button>
                    <Button Style="{StaticResource Invisible}" CommandParameter="{x:Static Spreadsheet:BorderType.BottomEdge}" Grid.Column="1" Grid.Row="2" Grid.ColumnSpan="3" VerticalAlignment="Bottom"  Height="20"></Button>
                    <Button Style="{StaticResource Invisible}" CommandParameter="{x:Static Spreadsheet:BorderType.InsideHorizontal}" Grid.Column="1" Grid.Row="1" Grid.ColumnSpan="3" VerticalAlignment="Center"  Height="20"></Button>
                </Grid>
            </GroupBox>
            
          <!--  <GroupBox Header="{x:Static Internals:UIStringTable.Border}" Grid.Column="1"></GroupBox> -->
        </Grid>


    </DataTemplate>

</ResourceDictionary>